/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Objects;

import java.text.SimpleDateFormat;
import java.util.Date;
/**
 *
 * @author CKCantillas
 */
public class ResidencyLog {
    private int resLogID;
    private String memberID;
    private String date;
    private String timeIn;
    private String timeOut;
    private float totalMinutes;

    public ResidencyLog() {
        this.resLogID = 0;
        this.memberID = "";
        this.date = "";
        this.timeIn = "";
        this.timeOut = "";
        this.totalMinutes = 0;
    }
    
    //remove if unnecessary
    public ResidencyLog(int id, String date, String timeIn) {
        this.resLogID = id;
        this.date = date;
        this.timeIn = timeIn;
    }
    
    public ResidencyLog(int resID, String memberID, String date, String timeIn, String timeOut) {
        this.resLogID = resID;
        this.memberID = memberID;
        this.date = date;
        this.timeIn = timeIn;
        this.timeOut = timeOut;
    }
    
    /**
     * @return the resLogID
     */
    public int getResLogID() {
        return resLogID;
    }

    /**
     * REMOVE IF UNNECESSARY
     * 
     * @param resLogID the resLogID to set
     */
    public void setResLogID(int resLogID) {
        this.resLogID = resLogID;
    }

    /**
     * @return the date
     */
    public String getDate() {
        return date;
    }

    /**
     * @param date the date to set
     */
    public void setDate(String date) {
        this.date = date;
    }

    /**
     * @return the timeIn
     */
    public String getTimeIn() {
        return timeIn;
    }

    /**
     * @param timeIn the timeIn to set
     */
    public void setTimeIn(String timeIn) {
        this.timeIn = timeIn;
    }

    /**
     * @return the timeOut
     */
    public String getTimeOut() {
        return timeOut;
    }

    /**
     * @param timeOut the timeOut to set
     */
    public void setTimeOut(String timeOut) {
        this.timeOut = timeOut;
    }

    /**
     * computes for the total minutes logged in
     * timeOut - timeIn
     * 
     * @return the totalMinutes
     */
    public float getTotalMinutes() {
        SimpleDateFormat sdf = new SimpleDateFormat("HH:mm:ss");
        
        if (this.timeOut != null && this.timeOut.length() > 0) {
            try {
                Date in = sdf.parse(this.timeIn);
                Date out = sdf.parse(this.timeOut);
                long diffLong = out.getTime() - in.getTime();
                float diffFloat = diffLong;
                diffFloat /= (1000 * 60);
                
                this.totalMinutes = diffFloat;
            } catch (Exception e) {
                System.err.println(e);
            }
        }
        
        
        return totalMinutes;
    }

    /**
     * REMOVE IF UNNECESSARY
     * 
     * @param totalMinutes the totalMinutes to set
     */
    public void setTotalMinutes(float totalMinutes) {
        this.totalMinutes = totalMinutes;
    }

    /**
     * @return the memberID
     */
    public String getMemberID() {
        return memberID;
    }

    /**
     * @param memberID the memberID to set
     */
    public void setMemberID(String memberID) {
        this.memberID = memberID;
    }
}
